<?php
/*
 * To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class Cerere {
	public $method, $params;

	public function __construct($params) {
		// $this->restful = (isset($params["restful"])) ? $params["restful"] : false;
		$this->method = $_SERVER["REQUEST_METHOD"];
		$this->parseRequest();
	}

	protected function parseRequest() {

		// grab JSON data if there...
		$this->params = (isset($_REQUEST['data'])) ? json_decode(stripslashes($_REQUEST['data'])) : null;

		if (isset($_REQUEST['data'])) {
			$this->params =  json_decode(stripslashes($_REQUEST['data']));
		} else {
			$raw  = '';
			$httpContent = fopen('php://input', 'r');
			//print_r($httpContent);
			while ($kb = fread($httpContent, 1024)) {
				$raw .= $kb;
			}
			$params = json_decode(stripslashes($raw));
			if ($params) {
				$this->params = $params->data;
			}
		}
	}
}
?>
